--[[
    玩家游戏实体
]]--

local blaze = require "blaze"
local game = require "club.threecard.texas"

local GameObject = require "entities.interfaces.GameObject"
local Client = require "entities.interfaces.Client"
local Player = require "entities.interfaces.Player"

local M = game.kbe.entity("TexaspokerPlayer", GameObject, Client, Player)

function M:__init__()
    GameObject.__init__(self)
    Client.__init__(self)
    Player.__init__(self)
end

--[[ =============================
             服务端接口
================================== ]]--

function M:operate(ope_id, value)
    value = value or 0
    self:cellCall('operate', ope_id, value)
end

--[[ =============================
             服务端回调
================================== ]]--

function M:onEnterSpace()
    game.store.room.player_enter(self)
end

function M:onEnterWorld()
    if self.id ~= blaze.kbe.player_id() then
        -- 自己进入使用onEnterSpace事件
        game.store.room.player_enter(self)
    end
end

function M:onDestroy()
    if self.id == blaze.kbe.player_id() then
        game.store.room.clear()
    end
end

function M:onLeaveWorld()
    game.store.room.player_leave(self)
end

function M:set_chip(old)
    game.store.ingame.on_set_chip({player = self, old = old, current = self.chip})
end

function M:on_deal(card_ids, action_sequence)
    self.log.debug(string.format("on_deal card_ids:%s  action_sequence:%s", game.dump(card_ids), game.dump(action_sequence)))
    game.store.ingame.on_deal({card_ids = card_ids, action_sequence = action_sequence})
end

function M:on_sync_handtype(handtype)
    self.log.debug("on_sync_handtype:"..handtype)
    game.store.ingame.on_sync_handtype(handtype)
end

function M:on_game_init(scene)
    self.log.info('game_init:'..game.dump(scene))
    game.store.ingame.on_game_init(scene)
end

return M